<!DOCTYPE html>
<html lang="en">
	<head>
    	<meta name="layout" content="main_pc">
        <title>火堆工作台</title>       
        <link rel="stylesheet" href="${resource(dir: 'css', file: 'user.center.css')}" type="text/css">
        <link rel="stylesheet" href="${resource(dir: 'css_pc', file: 'project.css')}" type="text/css">
        <link rel="stylesheet" type="text/css" href="${resource(dir: 'editerPlugin/simditor-2.2.4/styles', file: 'simditor.css')}" />
        <script type="text/javascript" src="${resource(dir: 'editerPlugin/simditor-2.2.4/lib', file: 'module.js')}"></script>
	    <script type="text/javascript" src="${resource(dir: 'editerPlugin/simditor-2.2.4/lib', file: 'hotkeys.js')}"></script>
	    <script type="text/javascript" src="${resource(dir: 'editerPlugin/simditor-2.2.4/lib', file: 'uploader.js')}"></script>
	    <script type="text/javascript" src="${resource(dir: 'editerPlugin/simditor-2.2.4/lib', file: 'simditor.js')}"></script>
		<script type="text/javascript" src="${resource(dir: 'js', file: 'jquery-1.10.2.js')}"></script>
	    <script type="text/javascript" src="${resource(dir: 'js', file: 'ajaxfileupload.js')}"></script>
    </head>
<body>

	<div class="container-fluid">

		<section class="quick-navi mb20">
			<div class="container">
				<a href="#" class="quick-link"><span>火堆工作台</span><span
					class="caret"></span></a>
				<!--a href="#" class="quick-link">联系我们</a-->
			</div>
		</section>

		<section>
			<div class="container mb50">
				
				<g:render template="navigate"   model="[status: status]"/>
							

				<div class="right-content" id="rightconsole">

					<div class="launch-container">
                <h3>编辑项目</h3>
                <div class="content">
                    <g:form id = "all-form"  action="dealProjectEdit" method="post"  id="" class="form-style3" target="_blank">
                       	<input type="hidden" name="projectid" value='${project.id}'>
                        <div class="form-item fix-width">
                            <label for="">类别<span class="tips"></span></label>
                            <div class="form-tips"></div>
                            <div class="form-ctrl">
                                <div class="select-ctrl">
                                    <select id="types" name="category">
                                    	<option value="100001" >教学物资</option>
                                    	<option value="100002" >培训活动</option>
                                    	<option value="100003" >学术创新</option>
                                    	<option value="100004" >其它</option>
                                    </select>
                                </div>
                             </div>
                        </div>
                        
                         <div class="form-item fix-width">
                            <label for="">标题    <font color="#BEBEBE">(不超过12个字)</font> <span class="tips"></span></label>
                            <div class="form-ctrl">
                                <input type="text" name="title" value='${project.name}'/>
                            </div>
                        </div>
                        
                        <div class="form-item fix-width">
                            <label for="">封面 <font color="#BEBEBE">(上传一张封面图片，应为JPG JEPG PNG格式，建议尺寸像素1920*1200)</font> <span class="tips"></span></label>
                            <div class="form-tips"></div>
                            <div class="form-ctrl">
                                <div class="img-box btn o no-border">
                                    +点击上传图片
                                    <input type="file" class="upload-cover" name="img-p" id="img-p">
                                </div>
                                <input type="hidden" name="img" id="img" value="">
                            </div>
                        </div>
                        <div class="form-item fix-width">
                        <label for="">预览<span class="tips"></span></label>
                        <div class="form-ctrl">
                        <div class="cover">
                            <div id="imgshow" class="img" style="width: 220px;min-height: 160px;background-size: cover;background-repeat: no-repeat;background-image:url(/scfire/project/imgRead?img=${project.img})"></div>
                        </div>
                        </div>
                        </div>
                        <div class="form-item fix-width">
                        <label for="">摘要 <font color="#BEBEBE">(不超过50字)</font> <span class="tips"></span></label>
                         <div class="form-ctrl">
                                <textarea  name="description" >${project.description}</textarea>
                         </div>
                        </div>
                        <div class="form-item">
                            <label for="">正文</label>
                            <div class="form-ctrl">
                                <div class="adjoined-bottom">
									<div class="grid-container">
										<div class="grid-width-100">
											<div id="editor" name="projectDetail">
											</div>
										</div>
									</div>
								</div>
                            </div>
                            <input id="projectDetail1" type="hidden" value="${project.detail}" name="content">
                            <div style="display:none" id="projectDetail"  >
                           
                            
                            
                            </div>
                        </div>
                        
                        <div class="form-item">
                            <div class="btn-container">
                            	<Button class="btn btn-save-all" name="preview" value="preview"> 预览</Button>
                              	<Button class="btn btn-save-all name="cancel" value="cancel"> 取消</Button>
                                <Button class="btn btn-save-all" name="submit" value="submit">提交</Button>
                            </div>
                        </div>
                    </g:form>
                    
                </div>
            </div>                           
            	</div>
                	
                	
			</div>
			<div class="clearboth"></div>
		</section>


	</div>

	<script type="text/javascript">
	toolbar = ['title', 'bold', 'italic', 'underline', 'strikethrough', 'color', '|',
		       	 'ol', 'ul', 'blockquote', 'code', 'table', '|',
		       	  'link', 'image', 'hr', '|',
		       	   'indent', 'outdent', 'alignment'];
     var editor = new Simditor( {
            textarea : $('#editor'),
            placeholder : '这里输入内容...',
            toolbar : toolbar,  //工具栏
            defaultImage : 'simditor-2.0.1/images/image.png', //编辑器插入图片时使用的默认图片
            upload : {
                url : '/scfire/project/imgSave', //文件上传的接口地址
                params: null, //键值对,指定文件上传接口的额外参数,上传的时候随文件一起提交
                fileKey: 'fileDataFileName', //服务器端获取文件数据的参数名
                connectionCount: 3,
                leaveConfirm: '正在上传文件'
            } 
        });

		$(function() {
			editor.setValue( $("#projectDetail1").val()+ $("#projectDetail").html());
			$('ul.nav.navbar-nav li').hover(
					function() {
						console.log($(this).index());
						$(this).siblings('.top-active').addClass(
								'position-' + $(this).index());
					},
					function() {
						$(this).siblings('.top-active').removeClass(
								'position-' + $(this).index());
			});

		     $('.img-box').on('change', 'input[type=file]' ,function(){
		         //the url is for test ....
		         posterStates = true;
		         var obj = $(this);
		         var file = obj.attr('id');
		         console.log("request:"+file);
		          $.ajaxFileUpload({  
		     			url:'/scfire/project/imgSaveMb',  
		     			secureuri:false,  
		     			dataType:'text',
		     			fileElementId:file,//file标签的id 
		     			success: function (data, status) { 
					           	if(data=='large'){
					           		showWarn('图片过大');
					           		return;
					           	}
					       		if(data=='format'){
					           		showWarn('图片格式不对');
					           		return;
					           	}
				               //把图片替换  
				               if(data=='fail'){
				               		showWarn('上传失败');
				               }else{
				            	   //图片预览
				            	   
				            	   console.log("return:"+data);
				                   var imageurl = "/scfire/project/imgRead?img="+data;	                   
				                   //图片地址赋值给后台
				                   $("#img").val(data);  
				                   
				                   $("#imgshow").css('background-image', 'url(' + imageurl + ')');
		             
				               }
				           },  
				           error: function (data, status, e) {  
				           },
		     	});
		     });
			//保存
	 		$('.btn-save-all').click(function(){
	 			//save context
	 			var data = editor.getValue();
	 			//alert(data)
	 	    	 $("#projectDetail1").val(data);
	 	    	
		 		//this.html('saving...');
		 		this.click(function(){});
	 			 //if(!checkNull()){
	 			 	//return;
	 			//}
	 	    	 //console.log(data);
	 	         $("#all-form").submit();
	 	         
	 	    });
		});

		

	</script>

</body>
</html>